package com.zt.page;

import java.util.ArrayList;
import java.util.List;

public class Page<T> {

	//当前页
	private int pageNo;
	//每页显示的条数
	private int pageSize = 3;
	//总条数
	private int totalNum;
	//集合数据
	private List<T> list = new ArrayList<>();
	
	//获取总页数
	public int getTotalPage() {
		//30/3=10 整除
		//30%3=0    取余
		int totalPage = getTotalNum() / pageSize;
		if(getTotalNum() % pageSize == 0) {
			return totalPage;
		}
		//返回总页数10页
		return totalPage + 1;
	}
	
	//获取首页
	public int getHome() {
		int home = 1;
		return home;
	}
	
	//获取尾页
	public int getEnd() {
		int end = getTotalPage();
		return end;
	}
		
	//获取上一页
	public int getPrePage() {
		if(getPageNo() > 1) {
			return getPageNo() - 1;
		}
		return getPageNo();
	}
	
	//获取下一页
	public int getNextPage() {
		if(getPageNo() < getTotalPage()) {
			return getPageNo() + 1;
		}
		return getPageNo();
	}
	
	//验证当前页(输入页数)
	public int getPageNo() {
		//这里进来以后是pageNo=1
		System.out.println("Page层pageNo="+pageNo);
		if(pageNo < 1) {//不执行
			return 1;
		}
		//getTotalPage总页数=10
		System.out.println("getTotalPage="+getTotalPage());
		if(pageNo > getTotalPage()) {//不执行
			return getTotalPage();
		}
		//返回页码 1   这里没执行
		return pageNo;
	}
	
	public void setPageNo(int pageNo) {
		this.pageNo = pageNo;
	}
	public int getPageSize() {
		return pageSize;
	}
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	public int getTotalNum() {
		return totalNum;
	}
	public void setTotalNum(int totalNum) {
		this.totalNum = totalNum;
		
	}
	public List<T> getList() {
		return list;
	}
	public void setList(List<T> list) {
		this.list = list;
	}

	@Override
	public String toString() {
		return "Page [pageNo=" + pageNo + ", pageSize=" + pageSize + ", totalNum=" + totalNum + ", list=" + list + "]";
	}
	
	
	
	
}
